package live.jialing.sip.message.box.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import live.jialing.core.beanvalidator.Second;
import live.jialing.data.core.JpaDomainEntity;
import live.jialing.data.jpa.LocalDateTimePersistenceConverter;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;

/**
 * 收件箱
 */
@Setter
@Getter
@ToString
@Entity
@Table(name = "message_in_box")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id", scope = InBox.class)
public class InBox extends JpaDomainEntity<Long> {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @NotNull(message = "id不能为空", groups = {Second.class})
    private Long id;

    /**
     * 发件人userId
     */
    private Long sender;

    /**
     * 收件人userId
     */
    private Long receiver;

    /**
     * 信息
     */
    @ManyToOne(fetch = FetchType.LAZY,optional = false)
    @JoinColumn(name = "info_id")
    private Information information;

    /**
     * 阅读时间
     */
    @Convert(converter = LocalDateTimePersistenceConverter.class)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSSSSS")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss.SSSSSS", timezone = "GMT+08:00")
    @Column(name = "read_time")
    private LocalDateTime readTime;

    /**
     * 短信发送时间
     */
    @Convert(converter = LocalDateTimePersistenceConverter.class)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSSSSS")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss.SSSSSS", timezone = "GMT+08:00")
    @Column(name = "send_sms_time")
    private LocalDateTime sendSmsTime;

    /**
     * 微信发送时间
     */
    @Convert(converter = LocalDateTimePersistenceConverter.class)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSSSSS")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss.SSSSSS", timezone = "GMT+08:00")
    @Column(name = "send_wx_time")
    private LocalDateTime sendWeixinTime;
}
